//
//  CinemaViewController.m
//  Fengly_Nuo_Movie
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 Fengly_Nuo. All rights reserved.
//

#import "CinemaViewController.h"
#import "CinemaTableViewCell.h"
#import "CinemaModel.h"


// MARK:VIEW_CENTER_X:屏中心x轴
#define VIEW_CENTER_X self.view.center.x

// MARK:VIEW_CENTER_Y:屏中心y轴
#define VIEW_CENTER_Y self.view.center.y

// MARK:HEIGHT:屏高
#define HEIGHT self.view.frame.size.height

// MARK:WIDTH:屏宽
#define WIDTH self.view.frame.size.width

@interface CinemaViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arrModels;;

@end

@implementation CinemaViewController

- (void)dealloc {
    [_arrModels release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 页面布局
    [self createCinemaVCAction];
    // 数据处理
    [self dataHundle];
    
}

// 页面布局
- (void)createCinemaVCAction {
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"影院";
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 59) style:(UITableViewStylePlain)];
    [self.view addSubview:_tableView];
    [_tableView release];
    
    [_tableView registerClass:[CinemaTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
}

// 数据处理
- (void)dataHundle {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"cinema" ofType:@"plist"];
    NSArray *arrDate = [NSArray arrayWithContentsOfFile:path];
    self.arrModels = [NSMutableArray array];
    for (NSDictionary *dic in arrDate) {
        CinemaModel *model = [CinemaModel cinemaModel];
        [model setValuesForKeysWithDictionary:dic];
        [_arrModels addObject:model];
    }
//    NSLog(@"%@", _arrModels);
}




#pragma mark - UITabelView Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _arrModels.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CinemaTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
//    cell.model = _arrModels[indexPath.row];
    CinemaModel *model = _arrModels[indexPath.row];
    cell.labelCinemaName.text = model.cinemaName;
    cell.labelAddress.text = model.address;
    cell.labelTelephone.text = model.telephone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CinemaModel *model = _arrModels[indexPath.row];
    
    // 求label 高度
    // 文字的大小，描述文字大小的信息
    NSDictionary *dicAddress = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:20], NSFontAttributeName, nil];
    // 通过文字大小 获取文本的高度
    CGRect rectAddress = [model.address boundingRectWithSize:CGSizeMake(WIDTH, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dicAddress context:nil];
    
    NSDictionary *dicCinemaName = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:30], NSFontAttributeName, nil];
    CGRect rectcinemaName = [model.cinemaName boundingRectWithSize:CGSizeMake(WIDTH, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dicCinemaName context:nil];
    
    NSDictionary *dicTelephone = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:20], NSFontAttributeName, nil];
    CGRect rectTelephone = [model.telephone boundingRectWithSize:CGSizeMake(WIDTH, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dicTelephone context:nil];
//    // 属性传值 将label高度给 bigLabelHelght
//    activityParticularsVC.bigLabelHelght = rect.size.height;
    
    return rectAddress.size.height + rectcinemaName.size.height + rectTelephone.size.height + 100;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
